﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;

/// <summary>
/// Summary description for Controller
/// </summary>
public class Controller<T>:UserControl
{
    T model;
    
    public T Model
    {
        set { Session["currentObject"] = value; }
        get {
            object o = Session["currentObject"];
            return (o==null)? model: (T)o;
        }
    }

    public void View(string page)
    {
        HttpContext.Current.Response.Redirect(DoAction.ActionWithPage(page));
    }
    public void View(string page, string action)
    {
        HttpContext.Current.Response.Redirect(DoAction.ActionPageView(page,action));
    }
    public void ViewMessage(List<Message> messages, MessageType type)
    {
       UserControl userControl = ((UserControl)this.FindControl("MessageBox1"));
       userControl.Visible = true;
       IMessage mes = (IMessage)userControl;
       mes.ShowMessage(messages,type);
    }

    public int GetID(string request)
    {
        object o = HttpContext.Current.Request[request];
        if (o == null) View("Warring");
        return int.Parse(o.ToString());

    }
}
